package com.chainyoung.component_tmtrade.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chainyoung.common.view.NoScrollListView;
import com.chainyoung.component_tmtrade.R;
import com.chainyoung.component_tmtrade.R2;
import com.chainyoung.component_tmtrade.bean.TradeCurrencyItem;
import com.chainyoung.component_tmtrade.bean.TradeCurrentDetail;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class TradeC2CAdapter extends RecyclerView.Adapter {

    private static final int TYPE_HEAD = 0;
    private static final int TYPE_MIDDLE = 1;
    private static final int TYPE_LIST = 2;


    private Context mContext;
    private List<TradeCurrencyItem> mAgencyList;
    private List<TradeCurrentDetail> tradeBuyList;
    private List<TradeCurrentDetail> tradeSellList;
    private LayoutInflater layoutInflater;

    private String coinTypeIn = "BTC", coinTypeOut = "BIT";
    private String newestPrice;


    public TradeC2CAdapter(Context context, List<TradeCurrencyItem> mList, List<TradeCurrentDetail> mBuyList, List<TradeCurrentDetail> mSellList,
    String coinTypeIn,String coinTypeOut,String newestPrice) {
        mContext = context;
        mAgencyList = mList;
        tradeBuyList = mBuyList;
        tradeSellList = mSellList;
        layoutInflater = LayoutInflater.from(mContext);
        this.coinTypeIn=coinTypeIn;
        this.coinTypeOut=coinTypeOut;
        this.newestPrice=newestPrice;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        switch (viewType) {
            case TYPE_HEAD:
                view = layoutInflater.inflate(R.layout.tmtrade_type_head, null);
                return new HeadHolder(view);
            case TYPE_MIDDLE:
                view = layoutInflater.inflate(R.layout.tmtrade_type_middle, null);
                return new MiddleHolder(view);
            case TYPE_LIST:
                view = layoutInflater.inflate(R.layout.tmtrade_list_agency_item, null);
                return new ListHolder(view);
        }
        return null;

    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

    }



    @Override
    public int getItemCount() {
        return mAgencyList.size() + 2;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_HEAD;
        } else if (position == 1) {
            return TYPE_MIDDLE;
        } else {
            return TYPE_LIST;
        }
    }

    class HeadHolder extends RecyclerView.ViewHolder {

        @BindView(R2.id.rb_buy_in)
        RadioButton rbBuyIn;
        @BindView(R2.id.rb_sell_out)
        RadioButton rbSellOut;
        @BindView(R2.id.tv_price_type)
        TextView tvPriceType;
        @BindView(R2.id.et_price)
        EditText etPrice;
        @BindView(R2.id.iv_add)
        ImageView ivAdd;
        @BindView(R2.id.iv_sub)
        ImageView ivSub;
        @BindView(R2.id.tv_num_type)
        TextView tvNumType;
        @BindView(R2.id.et_trade_num)
        EditText etTradeNum;
        @BindView(R2.id.tv_available_num)
        TextView tvAvailableNum;
        @BindView(R2.id.tv_total_type)
        TextView tvTotalType;
        @BindView(R2.id.tv_total_amount)
        TextView tvTotalAmount;
        @BindView(R2.id.tv_buy)
        TextView tvBuy;
        @BindView(R2.id.list_view_sell)
        NoScrollListView listViewSell;
        @BindView(R2.id.tv_total_money)
        TextView tvTotalMoney;
        @BindView(R2.id.list_view_buy)
        NoScrollListView listViewBuy;

        Unbinder unbinder;


        public HeadHolder(View itemView) {
            super(itemView);
            unbinder = ButterKnife.bind(itemView);
        }
    }

    class MiddleHolder extends RecyclerView.ViewHolder {

        @BindView(R2.id.txt_type)
        TextView txtType;
        @BindView(R2.id.txt_price)
        TextView txtPrice;
        @BindView(R2.id.txt_amount)
        TextView txtAmount;
        @BindView(R2.id.tv_check_record)
        TextView tvCheckRecord;

        Unbinder unbinder;


        public MiddleHolder(View itemView) {
            super(itemView);
            unbinder = ButterKnife.bind(itemView);
        }
    }

    class ListHolder extends RecyclerView.ViewHolder {

        @BindView(R2.id.tv_type)
        TextView tvType;
        @BindView(R2.id.tv_price)
        TextView tvPrice;
        @BindView(R2.id.tv_total)
        TextView tvTotal;
        @BindView(R2.id.tv_already)
        TextView tvAlready;
        @BindView(R2.id.tv_more)
        TextView tvMore;

        Unbinder unbinder;

        public ListHolder(View itemView) {
            super(itemView);
            unbinder = ButterKnife.bind(itemView);
        }
    }


}
